﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using fbasync.web.Data;

namespace fbasync.web.Controls.TemplateEditor
{
    public partial class TextEditBox : System.Web.UI.UserControl
    {
        public bool EditOnDemand { get; set; }
        
        public bool ReadOnly
        {
            get { return ((bool?)ViewState["ReadOnly"]).GetValueOrDefault(); }
            set { ViewState["ReadOnly"] = value; }
        }

        public string Text
        {
            get { return uiTextBox.Text; }
            set { uiTextBox.Text = value; }
        }

        public TextBoxMode TextMode
        {
            get { return uiTextBox.TextMode; }
            set { uiTextBox.TextMode = value; }
        }

        public string TextBoxCssClass
        {
            get { return uiTextBox.CssClass; }
            set { uiTextBox.CssClass = value; }
        }

        protected override void OnPreRender(EventArgs e)
        {
            base.OnPreRender(e);

            if (EditOnDemand)
            {
                uiTextBox.ReadOnly = true;
                uiToolbar.Visible = true;

                Page.ClientScript.RegisterClientScriptInclude("textBoxEditor", "Scripts/textEditBox.js");
            }
            else
            {
                uiTextBox.ReadOnly = ReadOnly;
                uiToolbar.Visible = false;
            }
        }

      
        internal void AssignStoryTemplate(TemplateEditorDataSet.OneLineTemplateRow oneLineTemplateRow)
        {
            uiTextBox.Text = oneLineTemplateRow.Title;
        }
    }
}